/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUISocios.java
 *
 * Created on 22/04/2011, 14:17:06
 */

package net.antoniopassos.dukeclube.visao.gui;

import java.awt.Dimension;
import java.beans.PropertyVetoException;
import net.antoniopassos.dukeclube.modelo.dominio.Socio;
import net.antoniopassos.dukeclube.modelo.dominio.constante.Constante;

/**
 *
 * @author Marlon
 */
public class GUISocios extends javax.swing.JInternalFrame {

    /** Creates new form GUISocios */
    public GUISocios() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tSocios = new javax.swing.JTable();
        bNovoSocio = new javax.swing.JButton();
        bVerDependentes = new javax.swing.JButton();
        bAlterarSocio = new javax.swing.JButton();
        bExcluirSocio = new javax.swing.JButton();
        pPesquisarSocio = new javax.swing.JPanel();
        iNome = new javax.swing.JLabel();
        tfNome = new javax.swing.JTextField();
        bPesquisarSocio = new javax.swing.JButton();

        setClosable(true);
        setTitle("Duke -Clube -socios");

        tSocios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tSocios);

        bNovoSocio.setText("Novo");
        bNovoSocio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bNovoSocioActionPerformed(evt);
            }
        });

        bVerDependentes.setText("Ver Dependentes");

        bAlterarSocio.setText("Alterar");

        bExcluirSocio.setText("Excluir");

        pPesquisarSocio.setBorder(javax.swing.BorderFactory.createTitledBorder("Pesquisa"));

        iNome.setText("Nome");

        bPesquisarSocio.setText("Pesquisar");

        javax.swing.GroupLayout pPesquisarSocioLayout = new javax.swing.GroupLayout(pPesquisarSocio);
        pPesquisarSocio.setLayout(pPesquisarSocioLayout);
        pPesquisarSocioLayout.setHorizontalGroup(
            pPesquisarSocioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pPesquisarSocioLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(iNome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tfNome, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bPesquisarSocio)
                .addContainerGap(69, Short.MAX_VALUE))
        );
        pPesquisarSocioLayout.setVerticalGroup(
            pPesquisarSocioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pPesquisarSocioLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(pPesquisarSocioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(iNome)
                    .addComponent(tfNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bPesquisarSocio))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(bNovoSocio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bAlterarSocio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bExcluirSocio)
                .addGap(321, 321, 321))
            .addGroup(layout.createSequentialGroup()
                .addComponent(bVerDependentes)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pPesquisarSocio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bNovoSocio)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(bAlterarSocio)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(bExcluirSocio)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                .addGap(5, 5, 5)
                .addComponent(pPesquisarSocio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bVerDependentes)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bNovoSocioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bNovoSocioActionPerformed
       Socio socio = new Socio();
       socio.setCodigo(Constante.NOVO);
       this.abrirGUICadastroDeSocio (socio);        // TODO add your handling code here:
    }//GEN-LAST:event_bNovoSocioActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bAlterarSocio;
    private javax.swing.JButton bExcluirSocio;
    private javax.swing.JButton bNovoSocio;
    private javax.swing.JButton bPesquisarSocio;
    private javax.swing.JButton bVerDependentes;
    private javax.swing.JLabel iNome;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pPesquisarSocio;
    private javax.swing.JTable tSocios;
    private javax.swing.JTextField tfNome;
    // End of variables declaration//GEN-END:variables

    private GUICadastroDeSocio guiCadastroDeSocio;

    public void setPosicao() {
        Dimension d = this.getDesktopPane().getSize();
        this.setLocation((d.width - this.getSize().width) / 6, (d.height -
        this.getSize().height) / 6);
    }

    private void abrirGUICadastroDeSocio (Socio socio) {
      if ((guiCadastroDeSocio == null) || (!guiCadastroDeSocio.isVisible())) {
         guiCadastroDeSocio = new GUICadastroDeSocio();
         OuvinteDeGUICadastroDeSocio ouvinte = new
         OuvinteDeGUICadastroDeSocio(guiCadastroDeSocio);
         this.getParent().add(guiCadastroDeSocio);
         guiCadastroDeSocio.setPosicao();
         guiCadastroDeSocio.setVisible(true);
         guiCadastroDeSocio.setSocio(socio);
      }
      try {
         guiCadastroDeSocio.setSelected(true);
      } catch (PropertyVetoException exc) {
          StringBuffer mensagem = new StringBuffer();
          mensagem.append("Não foi possível selecionar a janela de cadastro de sócio!");
          mensagem.append("\nMotivo: " + exc.getMessage());
          GUIMensagem.exibirMensagem(mensagem.toString(), "DukeClube - Cadastro de sócio", true);
       }
   }
}
